﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using nspLable.Manage;
using nspLable.Function;
using Expo;

public partial class Expo_Trade : System.Web.UI.Page
{
    public string _headstr = "";
    public string _typelike = "";
    public int ID = 0;
    public int expocount = 0;
    public DataTable expoTab = new DataTable();
    protected ArrayList expoArray = new ArrayList();
    public string prevPage = "";
    public string nextPage = "";
    public int PageIndex = 1;
    public int PageSize = 10;
    public int pagecount = 1;
    public string PageNav = "";
    public string strUrl = "";
    public string strWhere = "  W_Expo.Verify=1 and (datediff(hh,W_Expo.EndDate,getdate())<0) ";
    public string orderStr = "";
    public int ordertype = 0;
    public string time = "";
    public string pid = "";
    public string cid = "";
    public string aid = "";
    public string keyword = "";
    public string _footstr = "";
    public string _lowertype = "";
    public string _adStr = "";
    public DataTable NewexpoList = new DataTable();
    public DataTable HotIndustryList = new DataTable();
    public DataTable MarketsalesList = new DataTable();
    public DataTable PutPicMarkSale = new DataTable();
    public string typekind = "";
    public string year = "";
    public string month = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (HttpContext.Current.Request.QueryString["id"] != null && HttpContext.Current.Request.QueryString["id"] != "")
            {
                ID = Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);
            }
            if (HttpContext.Current.Request.QueryString["Page"] != null)
            {
                PageIndex = Convert.ToInt32(HttpContext.Current.Request.QueryString["Page"]);
            }
            if (HttpContext.Current.Request.QueryString["pid"] != null)
            {
                pid = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["pid"]);
            }
            if (HttpContext.Current.Request.QueryString["cid"] != null)
            {
                cid = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["cid"]);
            }
            if (HttpContext.Current.Request.QueryString["aid"] != null)
            {
                aid = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["aid"]);
            }
            if (HttpContext.Current.Request.QueryString["keyword"] != null)
            {
                keyword = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["keyword"]);
            }
            if (HttpContext.Current.Request.QueryString["regdate"] != null)
            {
                time = System.Web.HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString["regdate"]);
            }
            if (HttpContext.Current.Request.QueryString["ordertype"] != null)
            {
                ordertype = Convert.ToInt32(HttpContext.Current.Request.QueryString["ordertype"]);
            }
            if (HttpContext.Current.Request.QueryString["typekind"] != null)
            {
                typekind = HttpContext.Current.Request.QueryString["typekind"];
            }
            if (HttpContext.Current.Request.QueryString["year"] != null)
            {
                year = HttpContext.Current.Request.QueryString["year"];
            }
            if (HttpContext.Current.Request.QueryString["month"] != null)
            {
                month = HttpContext.Current.Request.QueryString["month"];
            }

            strUrl = Base.BasePage.Config.WebURL + "expo/trade" + Base.BasePage.Config.Rewrite + "?id=" + ID + "";

            if (pid != "" && pid != "0" && pid != "请选择省份")
            {
                strWhere += " and Province like '%" + pid + "%'";
                strUrl += "&pid=" + System.Web.HttpUtility.UrlEncode(pid);
            }
            if (cid != "" && cid != "0" && cid.Trim() != "请选择城市")
            {
                strWhere += " and City like '%" + cid + "%'";
                strUrl += "&cid=" + System.Web.HttpUtility.UrlEncode(cid);
            }
            if (aid != "" && aid != "0" && aid.Trim() != "请选择区域")
            {
                strWhere += " and Area like '%" + aid + "%'";
                strUrl += "&aid=" + System.Web.HttpUtility.UrlEncode(aid);
            }
            if (keyword != "")
            {
                strWhere += " and Title like '%" + keyword + "%'";
                strUrl += "&keyword=" + System.Web.HttpUtility.UrlEncode(keyword);
            }
            if (time == "超过5年")
            {
                strWhere += " and   (DATEDIFF(year, W_Expo.AddDate, GETDATE()) >= 5)";
                strUrl += "&regdate=" + System.Web.HttpUtility.UrlEncode(time);
            }
            if (time == "超过3年")
            {
                strWhere += " and   (DATEDIFF(year, W_Expo.AddDate, GETDATE()) >= 3)";
                strUrl += "&regdate=" + System.Web.HttpUtility.UrlEncode(time);
            }
            if (time == "超过2年")
            {
                strWhere += " and   (DATEDIFF(year, W_Expo.AddDate, GETDATE()) >= 2)";
                strUrl += "&regdate=" + System.Web.HttpUtility.UrlEncode(time);
            }
            if (time == "1年以下")
            {
                strWhere += " and   (DATEDIFF(year, W_Expo.AddDate, GETDATE()) <= 1)";
                strUrl += "&regdate=" + System.Web.HttpUtility.UrlEncode(time);
            }
            if (typekind != "")
            {
                strWhere += " and W_Expo.type=" + typekind;
                strUrl += "&typekind="+typekind;
            }
            if (year != "")
            {
                strWhere += " and (YEAR(W_Expo.StartDate) = " + year + ")  ";
                strUrl += "&year="+year;
            }
            if (month != "") {
                strWhere += " and (Month(W_Expo.StartDate) = " + month + ")  ";
                strUrl += "&month="+month;
            }
            if (ID != 0)
            {
               // strWhere += " and patindex('%,'+rtrim( " + ID + ")+',%',','+ IndType+',')>0 ";
                strWhere += " and W_Expo.TypeID=" + ID;
            }
            if (ordertype == 1)
            {
                orderStr = " order by W_Expo.AddDate Desc";
            }
            if (ordertype == 2)
            {
                orderStr = " order by W_Expo.AddDate Asc";
            }
            if (ordertype == 0)
            {
                orderStr = "";
            }
            strUrl += "&Page=";
            Bind();
            getHead();
            expoBind();
            getFoot();


            if (PageIndex == 1)
            {
                prevPage = strUrl + 1;
            }
            if (PageIndex > 1)
            {
                prevPage = strUrl + (PageIndex - 1);
            }

            if (PageIndex == pagecount)
            {
                nextPage = strUrl + PageIndex;
            }
            if (PageIndex < pagecount)
            {
                nextPage = strUrl + (PageIndex + 1);
            }
        }
    }

    private void Bind()
    {
        RExpo reo= new RExpo ();
        expoTab = reo.GetExpolist(strWhere, orderStr);
        _lowertype = reo.lowerType(ID);
        _typelike = reo.TypeLink(ID);
        DataTable dt = reo.GetAD(1, 23);
        foreach (DataRow dr in dt.Rows)
        {
            _adStr = "<a title=\"" + dr["Ad_Leter"] + "\" target=\"_blank\" href=\"" + dr["Ad_Adrees"] + "\"><img alt=\"" + dr["Ad_Leter"] + "\" width=\"" + dr["Ad_Width"] + "\" height=\"" + dr["Ad_Height"] + "\" src=\"" + dr["Ad_ImageAdrees"] + "\" /></a>";
        }
        NewexpoList = reo.GetZDGQInfo(8);
        MarketsalesList = reo.GetMarkSale(8);
        PutPicMarkSale = reo.GetPutPicMarkSale(1);
    }
    private void getHead()
    {
        TUserLable Temp = new RUserLable().GateItem("WS_整站头部");
        if (Temp.Info == null || Temp.Info == "")
            _headstr = "";
        else
            _headstr = Temp.Info.ToString();
        _headstr = _headstr.Replace("{PB_WebURL}", Base.BasePage.Config.WebURL);
    }
    private void getFoot()
    {
        TUserLable Temp = new RUserLable().GateItem("WS_整站底部");
        if (Temp.Info == null || Temp.Info == "")
            _footstr = "";
        else
            _footstr = Temp.Info.ToString();
        _footstr = _footstr.Replace("{PB_WebURL}", Base.BasePage.Config.WebURL);
    }
    private void expoBind()
    {
        expoArray.Clear();
        expoArray.AddRange(expoTab.Rows);    //每页品牌列表
        expocount = expoArray.Count;
        //获取总页数
        pagecount = expocount % PageSize == 0 ? expocount / PageSize : expocount / PageSize + 1;
        if (pagecount == 0) pagecount = 1;
        PageIndex = PageIndex < 1 ? 1 : PageIndex;
        PageIndex = PageIndex > pagecount ? pagecount : PageIndex;
        PageNav = Pagination.GoToPager(PageIndex, PageSize, strUrl, strWhere, " W_Expo left join U_UserInfo on W_Expo.UserID=U_UserInfo.UserID ");
        int pcount = PageSize;
        if (PageIndex * PageSize > expocount) pcount = PageSize - (PageIndex * PageSize - expocount);
        expoArray = expoArray.GetRange((PageIndex - 1) * PageSize, pcount);
    }
}
